home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / wdj0696.zip / ZOLMAN.ZIP / HINTTAG.CPP < prev    next >
C/C++ Source or Header  |  1996-02-19  |  5KB  |  187 lines

  1. // hinttag.cpp -- Example application using a control bar with hint tags
  2. //  by Brent W. York (sage@ameritel.net)
  3.  
  4. #include <owl\applicat.h>
  5. #include <owl\decframe.h>
  6. #include <owl\statusba.h>
  7. #include <owl\inputdia.h>
  8. #include <owl\chooseco.h>
  9. #include <owl\choosefo.h>
  10. #pragma hdrstop
  11.  
  12. #include "hinttag.rh"
  13. #include "hintbar.h"
  14.  
  15.  
  16. // Global custom color array for TChooseColorDialog
  17.  
  18. TColor custColors[16];
  19.  
  20.  
  21. //----------------------------------------------------------------------------
  22. //--- hintApp Definition
  23. //----------------------------------------------------------------------------
  24.  
  25. class hintApp : public TApplication
  26. {
  27. public:
  28.    hintApp(void);
  29.    virtual void InitMainWindow(void);
  30.  
  31.    void SetDelay(int n);
  32.    void SetTextColor(TColor color);
  33.    void SetBrushColor(TColor color);
  34.    TFont &GetFont(void) { return bar->GetFont(); }
  35.    void SetFont(TFont *font) { bar->SetFont(font); }
  36.  
  37.    int delay;
  38.    TColor textColor, brushColor;
  39.  
  40. private:
  41.    THintTagBar *bar;
  42. };
  43.  
  44.  
  45. //----------------------------------------------------------------------------
  46. //--- hintClient Definition
  47. //----------------------------------------------------------------------------
  48.  
  49. class hintClient : public TWindow
  50. {
  51. public:
  52.    hintClient(TModule* module = 0) : TWindow(0, 0, module) {}
  53.  
  54. protected:
  55.    void CmBkColor(void);
  56.    void CmTxColor(void);
  57.    void CmFont(void);
  58.    void CmDelay(void);
  59.    DECLARE_RESPONSE_TABLE(hintClient);
  60. };
  61.  
  62. //----------------------------------------------------------------------------
  63. //--- hintClient Implementation
  64. //----------------------------------------------------------------------------
  65.  
  66. DEFINE_RESPONSE_TABLE1(hintClient, TWindow)
  67.    EV_COMMAND(CM_BKCOLOR, CmBkColor),
  68.    EV_COMMAND(CM_TXCOLOR, CmTxColor),
  69.    EV_COMMAND(CM_FONT, CmFont),
  70.    EV_COMMAND(CM_DELAY, CmDelay),
  71. END_RESPONSE_TABLE;
  72.  
  73. void hintClient::CmBkColor(void)
  74. {
  75.    hintApp *theApp = TYPESAFE_DOWNCAST(GetApplication(), hintApp);
  76.    TChooseColorDialog::TData data;
  77.    data.Color = theApp->brushColor;
  78.    data.CustColors = custColors;
  79.    data.Flags = CC_RGBINIT;
  80.    if ((TChooseColorDialog(this, data, 0, "Hint Tag Background")).Execute()
  81.       == IDOK) theApp->SetBrushColor(data.Color);
  82. }
  83.  
  84. void hintClient::CmTxColor(void)
  85. {
  86.    hintApp *theApp = TYPESAFE_DOWNCAST(GetApplication(), hintApp);
  87.    TChooseColorDialog::TData data;
  88.    data.Color = theApp->textColor;
  89.    data.CustColors = custColors;
  90.    data.Flags = CC_RGBINIT;
  91.    if ((TChooseColorDialog(this, data, 0, "Hint Tag Text")).Execute()
  92.       == IDOK) theApp->SetTextColor(data.Color);
  93. }
  94.  
  95. void hintClient::CmFont(void)
  96. {
  97.    hintApp *theApp = TYPESAFE_DOWNCAST(GetApplication(), hintApp);
  98.    TChooseFontDialog::TData data;
  99.    theApp->GetFont().GetObject(data.LogFont);
  100.    data.Flags = CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT;
  101.    if ((TChooseFontDialog(this, data, 0, "Hint Tag Font")).Execute() == IDOK)
  102.       theApp->SetFont(new TFont(&(data.LogFont)));
  103. }
  104.  
  105. void hintClient::CmDelay(void)
  106. {
  107.    hintApp *theApp = TYPESAFE_DOWNCAST(GetApplication(), hintApp);
  108.    char buf[18];
  109.    itoa(theApp->delay, buf, 10);
  110.    if ((TInputDialog(this, "Hint Tag Delay",
  111.       "Enter new delay in milliseconds.", buf, 17)).Execute() == IDOK)
  112.          theApp->SetDelay(atoi(buf));
  113. }
  114.  
  115.  
  116. //----------------------------------------------------------------------------
  117. //--- hintApp Implementation
  118. //----------------------------------------------------------------------------
  119.  
  120. hintApp::hintApp(void) : TApplication("Hint Tag Example")
  121. {
  122.    delay = 1000;
  123.    textColor = TColor::Black;
  124.    brushColor = TColor(255,255,115);
  125.    custColors[0] = brushColor;
  126. }
  127.  
  128. void hintApp::SetDelay(int n)
  129. {
  130.    delay = n;
  131.    bar->SetTagDelay(delay);
  132. }
  133.  
  134. void hintApp::SetBrushColor(TColor color)
  135. {
  136.    brushColor = color;
  137.    bar->SetBrushColor(brushColor);
  138. }
  139.  
  140. void hintApp::SetTextColor(TColor color)
  141. {
  142.    textColor = color;
  143.    bar->SetTextColor(textColor);
  144. }
  145.  
  146. void hintApp::InitMainWindow(void)
  147. {
  148.    hintClient *client = new hintClient;
  149.    TDecoratedFrame *frame = new TDecoratedFrame(0, Name, client, true);
  150.    frame->AssignMenu(HINT_MENU);
  151.    bar = new THintTagBar(frame, TGadgetWindow::Horizontal,
  152.       new TGadgetWindowFont(6, true, false));
  153.    bar->Insert(*new THintButtonGadget(CM_BKCOLOR, CM_BKCOLOR,
  154.       "Background Color"));
  155.    bar->Insert(*new THintButtonGadget(CM_TXCOLOR, CM_TXCOLOR, "Text Color"));
  156.    bar->Insert(*new THintButtonGadget(CM_FONT, CM_FONT, "Font"));
  157.    bar->Insert(*new THintButtonGadget(CM_DELAY, CM_DELAY, "Hint Delay"));
  158.    bar->Insert(*new TSeparatorGadget(8));
  159.    bar->Insert(*new THintButtonGadget(CM_EXIT, CM_EXIT, "Exit"));
  160.    bar->SetHintMode(TGadgetWindow::EnterHints);
  161.    bar->Attr.Id = IDW_TOOLBAR;
  162.    bar->SetTagDelay(delay);
  163.    frame->Insert(*bar, TDecoratedFrame::Top);
  164.    TStatusBar *status = new TStatusBar(frame, TGadget::Plain, 0);
  165.    frame->Insert(*status, TDecoratedFrame::Bottom);
  166.    SetMainWindow(frame);
  167.    EnableCtl3d(true);
  168. }
  169.  
  170.  
  171. //----------------------------------------------------------------------------
  172. //--- OwlMain Function
  173. //----------------------------------------------------------------------------
  174.  
  175. int OwlMain (int, char* [])
  176. {
  177.    try {
  178.       hintApp app;
  179.       return app.Run();
  180.    }
  181.    catch (xmsg& x) {
  182.       ::MessageBox(0, x.why().c_str(), "Exception", MB_OK);
  183.    }
  184.    return -1;
  185. }
  186.  
  187.